#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlComponent>

#include "inputhandler.h"

int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif

    QGuiApplication app(argc, argv);

    //省略其他代码，关键代码如下：
    qmlRegisterType<InputHandler>("an.qml.TransObj", 1, 0, "TransObj");

    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);

//    InputHandler inputHandler;
//    QQmlComponent compont(&engine);
//    compont.loadUrl(QUrl(QString("qrc:/Window.qml")));
//    QObject *qmlWindow = compont.create();
//    qmlWindow->setParent(engine.rootObjects()[0]);
//    engine.rootContext()->setContextProperty("myObject", &inputHandler);



    return app.exec();
}
